package com.yc.annotation;

import java.lang.reflect.Method;

public class InfoTracker {
	public static void main(String[] args) {
		InfoTracker tracker = new InfoTracker();
		tracker.tracker(Demo.class);
	}
	public void tracker(Class<?> cls) {
		Info info = null;
		try {
			Object obj = cls.newInstance();
			for(Method method : cls.getDeclaredMethods()) { // 循环给定类的所有方法
				if(method.isAnnotationPresent(Info.class)) { // 判断这个方法上是否有Info注解
					info = method.getAnnotation(Info.class); // 获取这个方法上的注解
					System.out.println(info.id() + ":" + info.desc());
					
					if( info.id() == 3) {
						System.out.println(method.invoke(obj, 1, 2));
					}
				}
				
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
